package com.gin.kotlin.vegetables_kot.base

import androidx.recyclerview.widget.RecyclerView

class RecyclerViewScrollListener(
    private val scrollToBottomListener: ScrollToBottomListener? = null,
) : RecyclerView.OnScrollListener() {
    /**
     * 当结束滚动时
     * @param recyclerView RecyclerView
     * @param dx Int
     * @param dy Int
     */
    override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
        super.onScrolled(recyclerView, dx, dy)

        if (dy > 0 && !recyclerView.canScrollVertically(1)) {
            scrollToBottomListener?.onScrollToBottom()
        }
    }


    /**
     * 当滚动到底部时的回调
     */
    interface ScrollToBottomListener {
        fun onScrollToBottom()
    }
}